<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>学生点名统计</title>
    <style>
        :root {
            --primary-color: #4a6fa5;
            --secondary-color: #6e9de4;
            --accent-color: #f39c12;
            --light-color: #f5f7fa;
            --dark-color: #333;
            --success-color: #27ae60;
            --warning-color: #e74c3c;
            --border-color: #ddd;
            --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }
        
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            line-height: 1.6;
            color: var(--dark-color);
            background-color: var(--light-color);
            padding: 20px;
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
        }
        
        header {
            text-align: center;
            margin-bottom: 30px;
            padding: 20px;
            background-color: white;
            border-radius: 8px;
            box-shadow: var(--shadow);
        }
        
        h1 {
            color: var(--primary-color);
            margin-bottom: 10px;
        }
        
        .filters {
            background-color: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: var(--shadow);
            margin-bottom: 20px;
            display: flex;
            flex-wrap: wrap;
            gap: 15px;
            align-items: center;
        }
        
        .filter-group {
            flex: 1;
            min-width: 200px;
        }
        
        label {
            display: block;
            margin-bottom: 5px;
            font-weight: 600;
        }
        
        select, input {
            width: 100%;
            padding: 10px;
            border: 1px solid var(--border-color);
            border-radius: 4px;
            font-size: 16px;
        }
        
        button {
            background-color: var(--primary-color);
            color: white;
            border: none;
            padding: 10px 15px;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            transition: background-color 0.3s;
        }
        
        button:hover {
            background-color: var(--secondary-color);
        }
        
        .tabs {
            display: flex;
            margin-bottom: 20px;
            background-color: white;
            border-radius: 8px;
            overflow: hidden;
            box-shadow: var(--shadow);
        }
        
        .tab {
            padding: 15px 20px;
            cursor: pointer;
            background-color: white;
            border: none;
            flex: 1;
            text-align: center;
            font-weight: 600;
            transition: all 0.3s;
        }
        
        .tab.active {
            background-color: var(--primary-color);
            color: white;
        }
        
        .tab-content {
            display: none;
            padding: 20px;
            background-color: white;
            border-radius: 8px;
            box-shadow: var(--shadow);
            margin-bottom: 20px;
        }
        
        .tab-content.active {
            display: block;
        }
        
        .table-container {
            overflow-x: auto;
        }
        
        table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 20px;
        }
        
        th, td {
            padding: 12px 15px;
            text-align: left;
            border-bottom: 1px solid var(--border-color);
        }
        
        th {
            background-color: #f8f9fa;
            font-weight: 600;
            color: var(--dark-color);
        }
        
        tr:hover {
            background-color: #f5f5f5;
        }
        
        .badge {
            display: inline-block;
            padding: 4px 8px;
            border-radius: 4px;
            font-size: 14px;
            font-weight: 600;
        }
        
        .badge-primary {
            background-color: var(--primary-color);
            color: white;
        }
        
        .badge-success {
            background-color: var(--success-color);
            color: white;
        }
        
        .badge-warning {
            background-color: var(--warning-color);
            color: white;
        }
        
        .badge-danger {
            background-color: #d9534f;
            color: #fff;
        }
        
        @media (max-width: 768px) {
            .filters {
                flex-direction: column;
            }
            
            .tab {
                padding: 10px;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <h1>学生点名统计</h1>
            <p>按班级、日期和学生查看点名统计</p>
        </header>
        
        <div class="filters">
            <div class="filter-group">
                <label for="class-filter">班级筛选</label>
                <select id="class-filter">
                    <option value="all">全部班级</option>
                    {% for class_name in classes %}
                    <option value="{{ class_name }}">{{ class_name }}</option>
                    {% endfor %}
                </select>
            </div>
            
            <div class="filter-group">
                <label for="date-from">日期范围</label>
                <div style="display: flex; gap: 10px;">
                    <input type="date" id="date-from" style="flex: 1;">
                    <span style="align-self: flex-end; line-height: 1;">至</span>
                    <input type="date" id="date-to" style="flex: 1;">
                </div>
            </div>
            
            <div class="filter-group">
                <label for="student-filter">学生筛选</label>
                <input type="text" id="student-filter" placeholder="输入学生姓名">
            </div>
            
            <div class="filter-group">
                <label>&nbsp;</label>
                <button id="filter-btn">应用筛选</button>
            </div>
        </div>
        
        <div class="tabs">
            <button class="tab active" data-tab="class">按班级统计</button>
            <button class="tab" data-tab="date">按日期统计</button>
            <button class="tab" data-tab="student">按学生统计</button>
            <button class="tab" data-tab="class-student">班级-学生统计</button>
            <button class="tab" data-tab="date-student">日期-学生统计</button>
            <button class="tab" data-tab="class-date">班级-日期统计</button>
        </div>
        
        <div class="tab-content active" id="class-tab">
            <div class="table-container">
                <table>
                    <thead>
                        <tr>
                            <th>班级</th>
                            <th>总点名次数</th>
                            <th>最近点名时间</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for entry in class_stats %}
                        <tr>
                            <td>{{ entry.class_name }}</td>
                            <td>
                                <span class="badge badge-primary">{{ entry.total_attendances }}</span>
                            </td>
                            <td>
                                {% if entry.last_time %}
                                    {{ entry.last_time }}
                                {% else %}
                                    无记录
                                {% endif %}
                            </td>
                        </tr>
                        {% empty %}
                        <tr>
                            <td colspan="3">暂无数据</td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
        
        <div class="tab-content" id="date-tab">
            <div class="table-container">
                <table>
                    <thead>
                        <tr>
                            <th>日期</th>
                            <th>总点名次数</th>
                            <th>最近点名时间</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for entry in date_stats %}
                        <tr>
                            <td>{{ entry.timestamp__date }}</td>
                            <td>
                                <span class="badge badge-primary">{{ entry.total_attendances }}</span>
                            </td>
                            <td>
                                {% if entry.last_time %}
                                    {{ entry.last_time }}
                                {% else %}
                                    无记录
                                {% endif %}
                            </td>
                        </tr>
                        {% empty %}
                        <tr>
                            <td colspan="3">暂无数据</td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
        
        <div class="tab-content" id="student-tab">
            <div class="table-container">
                <table>
                    <thead>
                        <tr>
                            <th>学生姓名</th>
                            <th>总点名次数</th>
                            <th>最近点名时间</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for entry in student_stats %}
                        <tr>
                            <td>{{ entry.student_name }}</td>
                            <td>
                                <span class="badge badge-primary">{{ entry.total_attendances }}</span>
                            </td>
                            <td>
                                {% if entry.last_time %}
                                    {{ entry.last_time }}
                                {% else %}
                                    无记录
                                {% endif %}
                            </td>
                        </tr>
                        {% empty %}
                        <tr>
                            <td colspan="3">暂无数据</td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
        
        <div class="tab-content" id="class-student-tab">
            <div class="table-container">
                <table>
                    <thead>
                        <tr>
                            <th>班级</th>
                            <th>学生姓名</th>
                            <th>总点名次数</th>
                            <th>最近点名时间</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for entry in class_student_stats %}
                        <tr>
                            <td>{{ entry.class_name }}</td>
                            <td>{{ entry.student_name }}</td>
                            <td>
                                <span class="badge badge-primary">{{ entry.total_attendances }}</span>
                            </td>
                            <td>
                                {% if entry.last_time %}
                                    {{ entry.last_time }}
                                {% else %}
                                    无记录
                                {% endif %}
                            </td>
                        </tr>
                        {% empty %}
                        <tr>
                            <td colspan="4">暂无数据</td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
        
        <div class="tab-content" id="date-student-tab">
            <div class="table-container">
                <table>
                    <thead>
                        <tr>
                            <th>日期</th>
                            <th>学生姓名</th>
                            <th>总点名次数</th>
                            <th>最近点名时间</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for entry in date_student_stats %}
                        <tr>
                            <td>{{ entry.timestamp__date }}</td>
                            <td>{{ entry.student_name }}</td>
                            <td>
                                <span class="badge badge-primary">{{ entry.total_attendances }}</span>
                            </td>
                            <td>
                                {% if entry.last_time %}
                                    {{ entry.last_time }}
                                {% else %}
                                    无记录
                                {% endif %}
                            </td>
                        </tr>
                        {% empty %}
                        <tr>
                            <td colspan="4">暂无数据</td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
        
        <div class="tab-content" id="class-date-tab">
            <div class="table-container">
                <table>
                    <thead>
                        <tr>
                            <th>班级</th>
                            <th>日期</th>
                            <th>总点名次数</th>
                            <th>最近点名时间</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for entry in class_date_stats %}
                        <tr>
                            <td>{{ entry.class_name }}</td>
                            <td>{{ entry.timestamp__date }}</td>
                            <td>
                                <span class="badge badge-primary">{{ entry.total_attendances }}</span>
                            </td>
                            <td>
                                {% if entry.last_time %}
                                    {{ entry.last_time }}
                                {% else %}
                                    无记录
                                {% endif %}
                            </td>
                        </tr>
                        {% empty %}
                        <tr>
                            <td colspan="4">暂无数据</td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <script>
        // 切换标签功能
        document.querySelectorAll('.tab').forEach(tab => {
            tab.addEventListener('click', () => {
                // 移除所有active类
                document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
                document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
                
                // 添加active类到当前标签
                tab.classList.add('active');
                
                // 显示对应内容
                const tabId = tab.getAttribute('data-tab');
                document.getElementById(`${tabId}-tab`).classList.add('active');
            });
        });
        
        // 筛选功能
        document.getElementById('filter-btn').addEventListener('click', () => {
            const classFilter = document.getElementById('class-filter').value;
            const dateFrom = document.getElementById('date-from').value;
            const dateTo = document.getElementById('date-to').value;
            const studentFilter = document.getElementById('student-filter').value.toLowerCase();
            
            // 在实际应用中，这里应该发送请求到后端进行筛选
            // 这里仅作为示例，实际项目需要实现筛选逻辑
            alert(`筛选条件已设置:\n班级: ${classFilter}\n日期范围: ${dateFrom} 至 ${dateTo}\n学生: ${studentFilter}`);
        });
    </script>
</body>
</html>